import random
import datetime
def create_data(start,end):
    print(start.strftime('%Y-%m-%d %H:%M:%S'))
    print(end - datetime.timedelta(minutes=15))
    file = open("data.sql", "w", encoding='UTF-8')
    while end >= start:
        insert_time = end.strftime('%Y-%m-%d %H:%M:%S')
        pm_two_dot_five = random.randint(30,70)
        pm_ten = random.randint(30,70)
        temperature = random.randint(20,30)
        humidity = random.randint(50,80)

        text = ("insert into env_history_data(id,thiot_device_id,pm_two_dot_five,pm_ten,temperature,humidity,start_time,end_time,insert_time,update_time)values ({},'1001',{},{},{},{},'{}','{}','{}','{}');\n".format(random.randint(1000000000,9999999999),pm_two_dot_five,pm_ten,temperature,humidity,insert_time,insert_time,insert_time,insert_time))
        end = (end - datetime.timedelta(minutes=15))
        file.write(text)
    # 3. 关闭
    file.close()
now_time = datetime.datetime.now() + datetime.timedelta(days=3)
create_data(datetime.datetime.now(),now_time)